<template>
	<view class="back-view" @touchmove.stop.prevent="moveHandle">
		<view class="view-background"></view>
		<view class="white-view-back">
			<view class="top-back">
				<view class="top-name">{{pageTitle}}</view>
				<view class="close-back" @click="closeBtnAction">
					<image class="close-img" src="../../../../static/close.png"></image>
				</view>
			</view>

			<view class="top-line"></view>
			<view style="width: 100%;">
				<uni-forms ref="baseForm">

					<uni-forms-item label="参数名称：" labelWidth="100" labelAlign="right" required>
						<uni-easyinput disabled="true" v-model="classItem.name" placeholder="请填写" />
					</uni-forms-item>
					<uni-forms-item label="参数值：" labelWidth="100" labelAlign="right" required>
						<uni-easyinput v-model="value" placeholder="请填写" />
					</uni-forms-item>
					<uni-forms-item label="是否默认：" labelWidth="100" labelAlign="right" required>
						<view class="item-back">
							<radio-group @change="radioChange" style="display: flex;">
								<view class="radio-back" v-for="(item, index) in radios" :key="item.value">
									<radio color="#2DA9C5" style="transform:scale(0.7)" :value="item.value"
										:checked="index === current" />
									<view>{{item.name}}</view>
								</view>
							</radio-group>
						</view>
					</uni-forms-item>
				</uni-forms>
			</view>
			<view class="bottom-back">
				<view class="bottom-btn bottom-btn-cancel" @click="closeBtnAction">取消</view>
				<view class="bottom-btn" @click="requestRoleChildData">确定</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		components: {

		},
		props: {
			classItem: {
				type: Object,
				default: {}
			},
			selectItem: {
				type: Object,
				default: {}
			},
			editType: {
				type: String,
				default: 'add',
			},
		},
		data() {
			return {
				showMask: false,
				pageTitle: '添加',
				selectClass: {},
				value: '',
				radios: [{
						value: '0',
						name: '否',
						checked: 'true'
					},
					{
						value: '1',
						name: '是'
					},
				],
				current: 0
			}
		},
		onLoad() {

		},
		mounted() {
			if (this.editType == 'edit') {
				this.pageTitle = '编辑';
				this.value = this.selectItem.name;
				this.current =  parseInt(this.selectItem.def.code);	
			}else{
				this.value = '';
				this.current = 0;
			}
		},
		methods: {
			//添加网络请求
			async requestRoleChildData() {
				if (!this.value) {
					uni.showToast({
						title: '请填写参数值',
						icon: 'none'
					})
					return;
				}

				let _this = this
				let parmas = {
					'classifyId': this.classItem.id,
					'dictCode': this.classItem.code,
					'name': this.value,
					'value': this.value,
					'pid': 0,
					'id': _this.editType == 'edit' ? this.selectItem.id : '',
					'def': _this.current
				}
				console.log(parmas)
				const res = await this.$myRequest({
					url: "/comm/dict",
					method: _this.editType == 'edit' ? 'PUT' : 'POST',
					data: parmas,
				})
				console.log('返回结果', res)
				if (res.data.code == 200) {
					uni.showToast({
						title: _this.editType == 'edit' ? '编辑成功' : '添加成功'
					})
					_this.$emit("successBack");
					_this.closeBtnAction()
				}else{
					uni.showToast({
						title: res.data.msg,
						icon: 'error'
					})
				}
			},
			//是否默认
			radioChange: function(evt) {
				console.log(evt)
				for (let i = 0; i < this.radios.length; i++) {
					if (this.radios[i].value === evt.detail.value) {
						this.current = i;
						break;
					}
				}
				console.log('默认'+ this.current)
			},

			closeBtnAction() {
				this.$emit('clickAddClose')
			},
			moveHandle() {
				return true
			},

		},
	}
</script>

<style>
	.back-view {
		position: fixed;
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
		z-index: 199;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.view-background {
		position: absolute;
		width: 100%;
		height: 100%;
		z-index: 100;
		background-color: rgba(0, 0, 0, 0.3);
	}

	.white-view-back {
		width: 452px;
		height: 300px;
		padding: 24px;
		max-height: 400px;
		background-color: white;
		margin-top: -50px;
		border-radius: 4px;
		z-index: 101;
		position: absolute;
	}

	.top-back {
		display: flex;
		justify-content: space-between;
	}

	.top-name {
		font-size: 18px;
		font-weight: normal;
		color: #333333;

	}

	.close-back {
		cursor: pointer;
		width: 20px;
		height: 20px;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.close-img {
		width: 12px;
		height: 12px;
	}

	.top-line {
		height: 1px;
		background: #EEEEEE;
		width: 100%;
		margin-top: 20px;
		margin-bottom: 20px;
	}

	.bottom-back {

		bottom: 0px;
		width: 100%;
		display: flex;
		justify-content: flex-end;
		align-items: center;
		position: absolute;
		height: 60px;
		right: 16px;
	}

	.bottom-btn {
		cursor: pointer;
		width: 104px;
		height: 32px;
		background: #2DA9C5;
		border-radius: 2px;
		color: #FFFFFF;
		font-size: 14px;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.bottom-btn-cancel {
		cursor: pointer;
		margin-right: 10px;
		background: #FFFFFF;
		border: 1px solid #EEEEEE;
		color: #333333;
	}

	.item-back {
		width: 350px;
		display: flex;
		align-items: center;
		height: 100%;
	}

	.radio-back {
		display: flex;
		margin-right: 10px;
		align-items: center;
	}

	.customer-item {
		display: flex;
		margin-top: 8px;
		align-items: center;

	}

	.customer-back {
		min-width: 168px;
		height: 44px;
		background: #E8F7FB;
		border-radius: 4px;
		display: flex;
		align-items: center;
		margin-right: 10px;
	}

	.customer-img {
		width: 20px;
		height: 20px;
		border-radius: 50%;
		margin-left: 8px;
	}

	.customer-name {
		font-size: 12px;
		font-weight: 400;
		color: #666666;
		margin-left: 2px;
	}

	.customer-phone {
		font-size: 12px;
		font-weight: 400;
		color: #666666;
		margin-left: 4px;
	}

	.customer-close {
		width: 16px;
		height: 16px;
		margin-right: 2px;
		margin-left: auto;
	}

	.customer-item-back {
		display: flex;
		flex-wrap: wrap;

	}

	.selectLaw {
		font-size: 14px;
		border: 1px solid #DCDFE6;
		border-radius: 4px;
		padding: 6px 10px;
		position: relative;

		flex-direction: row;
		align-items: center;
		z-index: 100000;
		background-color: white;
	}

	.law-item-back {
		background-color: white;
	}

	.selectLaw-list {
		margin-top: 2px;
		position: absolute;
		width: 340px;
		height: 180px;
		z-index: 100010;
		background-color: white;
		box-shadow: 0px 2px 8px 0px rgba(0, 0, 0, 0.2000);
		border-radius: 2px;
	}

	.mask-view {
		position: absolute;
		width: 100vw;
		height: 100vh;
		z-index: 9999;
		background-color: rgba(0, 0, 0, 0.0);
		top: -100px;
		left: 0;
		right: 0;
		bottom: 0;

	}



	.pop-content-back {
		margin-top: 10px;
		height: 160px;
		margin-left: 20px;
		width: 300px;
	}

	.pop-content-list {
		display: flex;
		align-items: center;
		margin-bottom: 10px;
		margin-top: 10px;
	}

	
</style>
